package com.woniu.sharepark.common.controller;

import com.woniu.sharepark.common.JsonResult;
import com.woniu.sharepark.common.pojo.Login;
import com.woniu.sharepark.common.pojo.UserInfo;
import com.woniu.sharepark.common.service.UserInfoService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author DELL
 * @date 2019/6/12 11:16
 * version v1.0
 */
@Controller
@RequestMapping("userInfo")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    /**
    * 查找当前用户信息
    * @title activerUserInfo
    * @param
    * @return com.woniu.sharepark.common.pojo.UserInfo
    * @author DELL
    * @date 2019/6/12 11:22
    **/

    @RequestMapping("/activeUserInfo")
    @ResponseBody
    public UserInfo activerUserInfo(){

        Session session = SecurityUtils.getSubject().getSession();
        Login login = (Login) session.getAttribute("currentUser");
        UserInfo userInfo = userInfoService.selectUserInfoById(login.getUserInfo().getuId());
        return userInfo;
    }


    /**
     * 分享邀请链接接口，通过该接口获取当前用户的专属邀请链接
     * 为注册用户可以通过此链接注册，成为当前用户的邀请人员
     *
     * @param request 传入Request参数，获取当前Web路径
     * @return com.woniu.sharepark.common.JsonResult
     * @Author Zongjie.Li
     * @Date 2019/6/18
     * @Version 1.0
     */
    @ResponseBody
    @RequestMapping("/share")
    public JsonResult shareInviteUrl(HttpServletRequest request){
        return userInfoService.shareInviteUrl(request);
    }
}
